package o2o.delivery.filter;


import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ld
 */
@WebFilter(urlPatterns = "/o2o/action/delivery/orders/addOrder")//如果这里写@Compnent就是拦截所有请求
public class HttpServletFilter implements Filter {
 
    @Override
    public void init(FilterConfig filterConfig) {
    }
 
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        Map<String, String[]> m = new HashMap<String, String[]>(request.getParameterMap());
        ParameterServletRequestWrapper parameterRequestWrapper = new ParameterServletRequestWrapper((HttpServletRequest) request, m);
        //继续向后传递修改后的request,拦截器不能实现。
        chain.doFilter(parameterRequestWrapper, response);
    }
 
    @Override
    public void destroy() {
 
    }
}